home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: [Q] Best way to "define" flag values?
- Message-ID: <marnoldDLK19q.4EM@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <marnoldDLIv9w.1s4@netcom.com> <4du2ug$nqt@ixnews8.ix.netcom.com>
- Date: Sun, 21 Jan 1996 23:29:49 GMT
- Sender: marnold@netcom23.netcom.com
-
- wkdugan@ix.netcom.com (Bill Dugan) writes:
-
- >marnold@netcom.com (Matt Arnold) wrote:
-
- >snip
-
- >>However, I have never quite found a good substitute for declaring
- >>values for flags. Passing flags to a function, for instance, is
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- >>a very common construct, and it's typically arranged like so...
-
- >> #define FLAG_A 0x0001
- >> #define FLAG_B 0x0010
- >> #define FLAG_C 0x0100
-
- >snip
-
- >Look up bit fields in your C or C++ reference.
-
- Duh, I know what bit fields are, thank you very much. But, they are not
- very useful for passing flags to a function, which was the main gist of
- my posting (which was snipped).
-
- FLAGS flags; // assume this is a bit field
-
- flags.a = TRUE;
- flags.b = FALSE;
- flags.c = TRUE;
- FuncTakingFlags(flags);
-
- ...is NOT as convenient as the traditional ...
-
- FuncTakingFlags(FLAG_A | FLAG_C);
-
- The bit field apporach is far too verbose, in my opinion, and can make
- certain coding styles difficult to use (ie, you always have to declare a
- bit field to pass to functions, etc.). And, it's not as easy to combine
- multiple bit fields into a single result (as you can with integer flag
- values, using the bitwise OR operator, for instance).
-
- Can you show us an example of how using bit fields for passing flags to
- functions has some kind of clear advantage over #define'd bit values?
-
- Anyone have any better ideas?
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-
-